package com.yh.autobio.modules.adatper;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yh.autobio.R;
import com.yh.autobio.modules.bean.InvoiceBean;
import com.yh.autobio.modules.bean.ProductBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by john on 2018/3/6 0006. 10:58
 */

public class InvoiceProductAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context ctx;
    private List<ProductBean> datas;

    public InvoiceProductAdapter(Context ctx) {
        this.ctx = ctx;
        datas = new ArrayList<>();
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(ctx).inflate(R.layout.item_invoice_pro, parent,
                false);
        return new InverntoryViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof InverntoryViewHolder) {
            initView((InverntoryViewHolder) holder);
        }
    }

    @Override
    public int getItemCount() {
        if (datas != null && datas.size() > 0){
            return datas.size();
        }else {
            return 0;
        }
    }


    public void setData(List<ProductBean> data) {
        this.datas = data;
    }

    public List<ProductBean> getData() {
        return datas;
    }
    public void addProduct(ProductBean data) {
        datas.add(data);
        notifyItemInserted(datas.size());
    }
    private void initView(InverntoryViewHolder holder) {
        int position = holder.getAdapterPosition();
        ProductBean productBean = datas.get(position);
        holder.tvCpmc.setText(productBean.getFEntryName());
        holder.tvGgxh.setText(productBean.getFEntryModel());
        holder.tvDzsl.setText(productBean.getFEntryQty());
        holder.etSl.setText(productBean.getFDoneNumber()+"");

    }


    class InverntoryViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.ll_title)
        LinearLayout llTitle;
        @InjectView(R.id.tv_cpmc)
        TextView tvCpmc;
        @InjectView(R.id.tv_ggxh)
        TextView tvGgxh;
        @InjectView(R.id.tv_dzsl)
        TextView tvDzsl;
        @InjectView(R.id.et_sl)
        EditText etSl;

        public InverntoryViewHolder(View view) {
            super(view);
            ButterKnife.inject(this, view);
        }
    }
}
